﻿Imports System.Data.SqlClient
Public Class en_members_merchantsuccesscases
    Inherits System.Web.UI.Page
    Private sSQL As String
    Private objrd As SqlDataReader = Nothing
    Private objfind As New GetData
    Private ps As New PreparedStatement(sSQL)

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (Session("uid") <> Nothing And Session("uid") <> "") Then
            Dim title, content, strErr, memberId, companyId As String
            Dim createDate
            createDate = Now
            strErr = ""
            memberId = Session("uid")
            If (Request("editType") <> Nothing And Request("editType") <> "") Then
                If (Request("editType").Equals("delete")) Then
                    ps.strSql = "delete from company_successcase where id=@id"
                    ps.parameters.Clear()
                    ps.addParameter("id", Request("successId"))
                    objfind.es(ps, strErr)
                    MsgBox("delete successfully！")
                    Response.Redirect("members-merchantsuccesscaseslist.aspx")
                End If
            ElseIf (Request("successId") <> Nothing And Request("successId") <> "") Then
                ps.strSql = "select * from company_successcase where id=@id"
                ps.parameters.Clear()
                ps.addParameter("id", Request("successId"))
                Dim conn As SqlConnection = objfind.getConn()

                objrd = objfind.dr(ps, strErr, conn, objrd)
                If (objrd.Read()) Then
                    c_id.Value = Request("successId")
                    c_title.Text = objrd.Item("title")
                    merchantsuccess.InnerHtml = objrd.Item("context")
                End If
                objfind.closeConn(conn)

            End If
            If (Request("submitmerchantsuccess") <> Nothing And Request("submitmerchantsuccess") <> "") Then
                If (Request("c_title") = "" Or Request("c_title") = Nothing) Then
                    Me.c_title_label.Text = "please enter title！"
                    Exit Sub
                Else
                    Me.c_title_label.Text = ""
                End If
                title = Request("c_title")
                content = Request("c_content")
                ps.strSql = "select * from merchant where owner_id =@ownerId"
                ps.addParameter("ownerId", memberId)
                Dim conn As SqlConnection = objfind.getConn()

                objrd = objfind.dr(ps, strErr, conn, objrd)
                If (objrd.Read()) Then
                    companyId = objrd.Item("company_id")
                End If
                If (Request("c_id") <> Nothing And Request("c_id") <> "") Then
                    ps.strSql = "update company_successcase set title=@title, context=@context where id=@id"
                    ps.parameters.Clear()
                    ps.addParameter("title", title)
                    ps.addParameter("context", content)
                    ps.addParameter("id", Request("c_id"))
                    objfind.es(ps, strErr)
                Else
                    ps.strSql = "insert into company_successcase(company_id,lang_flag,title,context,create_date)" & _
                        "values(@companyId,'en',@title,@context,@createDate)"
                    ps.parameters.Clear()
                    ps.addParameter("companyId", companyId)
                    ps.addParameter("title", title)
                    ps.addParameter("context", content)
                    ps.addParameter("createDate", createDate)
                    objfind.es(ps, strErr)
                End If
                objfind.closeConn(conn)

                Response.Redirect("members-merchantsuccesscaseslist.aspx")
            End If
            Else
                Response.Redirect("../login.aspx")
            End If
    End Sub

End Class